<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Collecting Elasticsearch monitoring data with Metricbeat | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'configuring-metricbeat.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/configuring-metricbeat.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/configuring-metricbeat.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/configuring-metricbeat.html" rel="nofollow" target="_blank">../en/configuring-metricbeat.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="monitor-elasticsearch-cluster.html">Monitor a cluster</a></span>
»
<span class="breadcrumb-node">Collecting Elasticsearch monitoring data with Metricbeat</span>
</div>
<div class="navheader">
<span class="prev">
<a href="monitoring-production.html">« Monitoring in a production environment</a>
</span>
<span class="next">
<a href="configuring-filebeat.html">Collecting Elasticsearch log data with Filebeat »</a>
</span>
</div>
<div class="chapter xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="configuring-metricbeat"></a>Collecting Elasticsearch monitoring data with Metricbeat<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/monitoring/configuring-metricbeat.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>

<p>In 6.5 and later, you can use Metricbeat to collect data about Elasticsearch
and ship it to the monitoring cluster, rather than routing it through exporters
as described in <a class="xref" href="collecting-monitoring-data.html" title="Collecting monitoring data using legacy collectors"><em>Legacy collection methods</em></a>.</p>
<div class="imageblock">
<div class="content">
<img src="../static/monitoring/images/metricbeat.png" alt="Example monitoring architecture">
</div>
</div>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
<p>Enable the collection of monitoring data.<br></p>
<p>Set <code class="literal">xpack.monitoring.collection.enabled</code> to <code class="literal">true</code> on the
production cluster. By default, it is is disabled (<code class="literal">false</code>).</p>
<p>You can use the following APIs to review and change this setting:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET _cluster/settings

PUT _cluster/settings
{
  "persistent": {
    "xpack.monitoring.collection.enabled": true
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1140.console"></div>
<p>If Elasticsearch security features are enabled, you must have <code class="literal">monitor</code> cluster privileges to
view the cluster settings and <code class="literal">manage</code> cluster privileges to change them.</p>
<p>For more information, see <a class="xref" href="monitoring-settings.html" title="Monitoring settings in Elasticsearch">Monitoring settings</a> and <a class="xref" href="cluster-update-settings.html" title="Cluster update settings API">Cluster update settings</a>.</p>
</li>
<li class="listitem">
<a href="https://www.elastic.co/guide/en/beats/metricbeat/7.7/metricbeat-installation.html" class="ulink" target="_top">Install Metricbeat</a> on each
Elasticsearch node in the production cluster.
</li>
<li class="listitem">
<p>Enable the Elasticsearch X-Pack module in Metricbeat on each Elasticsearch node.<br></p>
<p>For example, to enable the default configuration in the <code class="literal">modules.d</code> directory,
run the following command:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">metricbeat modules enable elasticsearch-xpack</pre>
</div>
<p>For more information, see
<a href="https://www.elastic.co/guide/en/beats/metricbeat/7.7/configuration-metricbeat.html" class="ulink" target="_top">Specify which modules to run</a> and
<a href="https://www.elastic.co/guide/en/beats/metricbeat/7.7/metricbeat-module-elasticsearch.html" class="ulink" target="_top">Elasticsearch module</a>.</p>
</li>
<li class="listitem">
<p>Configure the Elasticsearch X-Pack module in Metricbeat on each Elasticsearch node.<br></p>
<p>The <code class="literal">modules.d/elasticsearch-xpack.yml</code> file contains the following settings:</p>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">  - module: elasticsearch
    metricsets:
      - ccr
      - cluster_stats
      - index
      - index_recovery
      - index_summary
      - ml_job
      - node_stats
      - shard
      - enrich
    period: 10s
    hosts: ["http://localhost:9200"]
    #username: "user"
    #password: "secret"
    xpack.enabled: true</pre>
</div>
<p>By default, the module collects Elasticsearch monitoring metrics from
<code class="literal">http://localhost:9200</code>. If that host and port number are not correct, you must
update the <code class="literal">hosts</code> setting. If you configured Elasticsearch to use encrypted
communications, you must access it via HTTPS. For example, use a <code class="literal">hosts</code> setting
like <code class="literal">https://localhost:9200</code>.</p>
<p>If Elastic security features are enabled, you must also provide a user ID
and password so that Metricbeat can collect metrics successfully:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Create a user on the production cluster that has the
<a class="xref" href="built-in-roles.html" title="Built-in roles"><code class="literal">remote_monitoring_collector</code> built-in role</a>.
Alternatively, use the
<a class="xref" href="built-in-users.html" title="Built-in users"><code class="literal">remote_monitoring_user</code> built-in user</a>.
</li>
<li class="listitem">
Add the <code class="literal">username</code> and <code class="literal">password</code> settings to the Elasticsearch module configuration
file.
</li>
</ol>
</div>
</li>
<li class="listitem">
<p>Optional: Disable the system module in Metricbeat.</p>
<p>By default, the <a href="https://www.elastic.co/guide/en/beats/metricbeat/7.7/metricbeat-module-system.html" class="ulink" target="_top">system module</a> is
enabled. The information it collects, however, is not shown on the <span class="strong strong"><strong>Monitoring</strong></span>
page in Kibana. Unless you want to use that information for other purposes, run
the following command:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">metricbeat modules disable system</pre>
</div>
</li>
<li class="listitem">
<p>Identify where to send the monitoring data.<br></p>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>In production environments, we strongly recommend using a separate cluster
(referred to as the <em>monitoring cluster</em>) to store the data. Using a separate
monitoring cluster prevents production cluster outages from impacting your
ability to access your monitoring data. It also prevents monitoring activities
from impacting the performance of your production cluster.</p>
</div>
</div>
<p>For example, specify the Elasticsearch output information in the Metricbeat
configuration file (<code class="literal">metricbeat.yml</code>):</p>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["http://es-mon-1:9200", "http://es-mon2:9200"] <a id="CO438-1"></a><i class="conum" data-value="1"></i>

  # Optional protocol and basic auth credentials.
  #protocol: "https"
  #username: "elastic"
  #password: "changeme"</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO438-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>In this example, the data is stored on a monitoring cluster with nodes
<code class="literal">es-mon-1</code> and <code class="literal">es-mon-2</code>.</p>
</td>
</tr>
</table>
</div>
<p>If you configured the monitoring cluster to use encrypted communications, you
must access it via HTTPS. For example, use a <code class="literal">hosts</code> setting like
<code class="literal">https://es-mon-1:9200</code>.</p>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>The Elasticsearch monitoring features use ingest pipelines, therefore the
cluster that stores the monitoring data must have at least one
<a class="xref" href="ingest.html" title="Ingest node">ingest node</a>.</p>
</div>
</div>
<p>If Elasticsearch security features are enabled on the monitoring cluster, you must
provide a valid user ID and password so that Metricbeat can send metrics
successfully:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Create a user on the monitoring cluster that has the
<a class="xref" href="built-in-roles.html" title="Built-in roles"><code class="literal">remote_monitoring_agent</code> built-in role</a>.
Alternatively, use the
<a class="xref" href="built-in-users.html" title="Built-in users"><code class="literal">remote_monitoring_user</code> built-in user</a>.
</li>
<li class="listitem">
Add the <code class="literal">username</code> and <code class="literal">password</code> settings to the Elasticsearch output information in
the Metricbeat configuration file.
</li>
</ol>
</div>
<p>For more information about these configuration options, see
<a href="https://www.elastic.co/guide/en/beats/metricbeat/7.7/elasticsearch-output.html" class="ulink" target="_top">Configure the Elasticsearch output</a>.</p>
</li>
<li class="listitem">
<a href="https://www.elastic.co/guide/en/beats/metricbeat/7.7/metricbeat-starting.html" class="ulink" target="_top">Start Metricbeat</a> on each node.
</li>
<li class="listitem">
<p>Disable the default collection of Elasticsearch monitoring metrics.<br></p>
<p>Set <code class="literal">xpack.monitoring.elasticsearch.collection.enabled</code> to <code class="literal">false</code> on the
production cluster.</p>
<p>You can use the following API to change this setting:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT _cluster/settings
{
  "persistent": {
    "xpack.monitoring.elasticsearch.collection.enabled": false
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1141.console"></div>
<p>If Elasticsearch security features are enabled, you must have <code class="literal">monitor</code> cluster
privileges to  view the cluster settings and <code class="literal">manage</code> cluster privileges
to change them.</p>
</li>
<li class="listitem">
<a href="https://www.elastic.co/guide/en/kibana/7.7/monitoring-data.html" class="ulink" target="_top">View the monitoring data in Kibana</a>.
</li>
</ol>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="monitoring-production.html">« Monitoring in a production environment</a>
</span>
<span class="next">
<a href="configuring-filebeat.html">Collecting Elasticsearch log data with Filebeat »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>